﻿@{
    ViewBag.Title = "考试管理";
    Exam exam = ViewBag.exam;
    List<PMP.Models.ViewModel.ViewExamQuest> list = ViewBag.list;
}
<style>
    #tab1 th, #tab1 td {
        text-align: center;
    }

        #tab1 td.left {
            text-align: left;
        }

        #tab1 td.right {
            text-align: right;
        }
</style>

<div>
    <a href="@Url.Action("Manager")" class="layui-btn">返回考试管理</a>
</div>
<div>
    @exam.Name
</div>
<div>
    <button class="layui-btn" onclick="add();">添加题目</button>
    <a href="@Url.Action("RelSort", new { ID = exam.ID })" class="layui-btn">题目排序</a>
</div>
<table id="tab1" class="layui-table">
    <thead>
        <tr>
            <th width="10%">序号</th>
            <th width="10%">ID</th>
            <th>题目</th>
            <th width="20%">操作</th>
        </tr>
    </thead>
    <tbody>
        @{
            int idx = 0;
        }
        @foreach (var q in list)
        {
            idx++;
            <tr rid="@q.ID" eid="@q.EID" qid="@q.QID">
                <td>@idx</td>
                <td>@q.QID</td>
                <td class="left">
                    @q.Title
                    <br />
                    @q.OptionA
                    <br />
                    @q.OptionB
                    <br />
                    @q.OptionC
                    <br />
                    @q.OptionD
                    <br />
                    答案： @q.Answer
                    <br />
                    @q.Analysis
                    <br />
                    @q.Point
                </td>
                <td><button class="layui-btn layui-btn-xs layui-btn-danger" onclick="remove(this);"><i class="layui-icon layui-icon-reduce-circle"></i>移除</button></td>
            </tr>
        }
    </tbody>
</table>


<div id="divtxt" style="display:none;">
    <div class="layui-form" style="margin:1em; padding:1em; ">
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">题目ID</label>
            <div class="layui-input-block">
                <textarea id="txtArea" placeholder="请输入题目ID，每个ID一行" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" id="btnok" onclick="ok();"><i class="layui-icon layui-icon-ok"></i>确定</button>
                <button class="layui-btn" id="btncancel"><i class="layui-icon layui-icon-close"></i>取消</button>
            </div>
        </div>
    </div>
</div>
@section script{
    <script>
		function remove(ele) {
            let tr = $(ele).parent().parent();
            let obj = new Object();
            obj.ID = tr.attr("rid");
            obj.EID = tr.attr("eid");
            obj.QID = tr.attr("qid");
            layer.msg("正在保存，请稍候...", {
                icon: 16,
                time: 0,
                shade: 0.3,
                shadeClose: false
            });
			$.ajax({
				type: "POST",
				url: "@Url.Action("RemoveRel")",
				data: obj,
                success: function (result) {
                    tr.remove();
					layer.msg(result.msg);
				},
				error: function (err) {
					layer.msg(err.responseText);
				}
			});
        }


        function add() {
            let winw = window.innerWidth * 0.6;
            let winh = window.innerHeight * 0.6;
            $("#txtArea").css("height", (winh - 120) + "px");
            let index = layer.open({
                type: 1,
                area: [winw + 'px', winh + 'px'],
                shade: false,
                title: false, //不显示标题
                content: $('#divtxt')
            });
            $("#btncancel").click(function () {
                layer.close(index);
            });
        }
        function ok() {
            let text = $("#txtArea").val();
            let arr = text.split("\n");

            let obj = new Object();
            obj.eid = @exam.ID;
            obj.ids = arr.join(",");
            layer.msg("正在保存，请稍候...", {
                icon: 16,
                time: 0,
                shade: 0.3,
                shadeClose: false
            });
			$.ajax({
				type: "POST",
				url: "@Url.Action("AddRel",new { EID=exam.ID})",
				data: obj,
                success: function (result) {
					layer.msg(result.msg);
				},
				error: function (err) {
					layer.msg(err.responseText);
				}
            });
            //$('#btncancel').click();
        }
    </script>
}